#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

def configure_api_keys():
    """配置API密钥"""
    
    print("配置API密钥...")
    print("=" * 50)
    
    # 设置环境变量
    os.environ['DASHSCOPE_API_KEY'] = 'sk-2c036d80d14a443f8769e072bb09a2e1'
    os.environ['MY_XXW_BGCX_API_KEY'] = 'Ii875XV8f7BomLGhgg1obwMD1Whbcr'
    
    print("✅ API密钥配置完成！")
    print(f"DASHSCOPE_API_KEY: {os.environ['DASHSCOPE_API_KEY'][:10]}...")
    print(f"MY_XXW_BGCX_API_KEY: {os.environ['MY_XXW_BGCX_API_KEY'][:10]}...")
    
    return True

def test_xueli():
    """测试xueli.py文件"""
    
    print("\n测试xueli.py文件...")
    print("-" * 30)
    
    try:
        # 导入xueli模块
        from ai_resume_generator import xueli
        
        print("✅ 成功导入xueli模块")
        
        # 测试verify_education函数
        print("\n测试verify_education函数...")
        test_args = {"vcode": "A7FKKV3C4Q40RWGD"}
        
        result = xueli.verify_education(test_args)
        print(f"✅ verify_education函数执行成功")
        print(f"返回结果: {result}")
        
        # 测试get_ai_response函数
        print("\n测试get_ai_response函数...")
        test_messages = [{"role": "user", "content": "学历验证:A7FKKV3C4Q40RWGD"}]
        
        completion = xueli.get_ai_response(test_messages)
        print(f"✅ get_ai_response函数执行成功")
        print(f"模型: {completion.model}")
        print(f"选择数量: {len(completion.choices)}")
        
        # 运行main函数
        print("\n运行main函数...")
        xueli.main()
        
    except Exception as e:
        print(f"❌ 测试失败: {str(e)}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    # 配置API密钥
    configure_api_keys()
    
    # 测试xueli.py
    test_xueli()
    
    print("\n" + "=" * 50)
    print("配置和测试完成！")
